@echo off
chcp 65001
echo ========================================
echo CenCat SaaS平台启动脚本
echo @author cencat
echo @version 1.0
echo @since 2024-12-19
echo ========================================
echo.

echo 正在检查Java环境...
java -version
if %errorlevel% neq 0 (
    echo 错误：未找到Java环境，请先安装JDK 17或更高版本
    pause
    exit /b 1
)

echo 正在检查Maven环境...
mvn -version
if %errorlevel% neq 0 (
    echo 错误：未找到Maven环境，请先安装Maven
    pause
    exit /b 1
)

echo.
echo 开始编译项目...
call mvn clean compile -DskipTests
if %errorlevel% neq 0 (
    echo 编译失败，请检查代码
    pause
    exit /b 1
)

echo.
echo 编译成功！
echo.
echo 可用的启动选项：
echo 1. 启动订单模块 (端口: 8080)
echo 2. 启动司机模块 (端口: 8081) 
echo 3. 启动路由模块 (端口: 8082)
echo 4. 启动所有模块
echo 5. 退出
echo.

set /p choice=请选择要启动的模块 (1-5): 

if "%choice%"=="1" (
    echo 启动订单模块...
    cd cencat-order
    start "CenCat Order Service" cmd /k "mvn spring-boot:run"
    cd ..
    echo 订单模块启动中，请查看新窗口...
    echo 接口文档地址: http://localhost:8080/api/order/swagger-ui.html
) else if "%choice%"=="2" (
    echo 启动司机模块...
    cd cencat-driver
    start "CenCat Driver Service" cmd /k "mvn spring-boot:run"
    cd ..
    echo 司机模块启动中，请查看新窗口...
    echo 接口文档地址: http://localhost:8081/api/driver/swagger-ui.html
) else if "%choice%"=="3" (
    echo 启动路由模块...
    cd cencat-route
    start "CenCat Route Service" cmd /k "mvn spring-boot:run"
    cd ..
    echo 路由模块启动中，请查看新窗口...
    echo 接口文档地址: http://localhost:8082/api/route/swagger-ui.html
) else if "%choice%"=="4" (
    echo 启动所有模块...
    
    echo 启动订单模块...
    cd cencat-order
    start "CenCat Order Service" cmd /k "mvn spring-boot:run"
    cd ..
    
    timeout /t 5 /nobreak >nul
    
    echo 启动司机模块...
    cd cencat-driver
    start "CenCat Driver Service" cmd /k "mvn spring-boot:run"
    cd ..
    
    timeout /t 5 /nobreak >nul
    
    echo 启动路由模块...
    cd cencat-route
    start "CenCat Route Service" cmd /k "mvn spring-boot:run"
    cd ..
    
    echo.
    echo 所有模块启动中，请查看各个窗口...
    echo.
    echo 接口文档地址：
    echo 订单模块: http://localhost:8080/api/order/swagger-ui.html
    echo 司机模块: http://localhost:8081/api/driver/swagger-ui.html
    echo 路由模块: http://localhost:8082/api/route/swagger-ui.html
) else if "%choice%"=="5" (
    echo 退出启动脚本
    exit /b 0
) else (
    echo 无效选择，请重新运行脚本
)

echo.
echo 启动完成！
echo 提示：关闭此窗口不会停止服务，请在各服务窗口中按 Ctrl+C 停止服务
pause